package online.hxstart.code.concurrent.chapter03;

import java.util.concurrent.TimeUnit;

/**
 * @author huxing
 * @date 19-4-23 星期二 下午6:08
 * @describe
 */
public class ThreadInterrupted {
  public static void main(String[] args) {
    /*    Thread thread =
        new Thread() {
          @Override
          public void run() {
            while (true) {
              System.out.println(Thread.interrupted());
            }
          }
        };
    thread.setDaemon(true);
    // thread.start();

    TimeUnit.MILLISECONDS.sleep(2);

    thread.interrupt();*/

    System.out.println("Main thread is interrupted? " + Thread.interrupted());

    Thread.currentThread().interrupt();

    System.out.println("Main thread is interrupted? " + Thread.currentThread().isInterrupted());

    try {
      TimeUnit.MINUTES.sleep(1);
    } catch (InterruptedException e) {
      e.printStackTrace();
      System.out.println("I will be interrupted still.");
    }
  }
}
